import os
from datetime import datetime, timedelta
from pathlib import Path


def create_folder_structure(base_path, start_date, end_date, subfolder_range):
    """
    创建指定的目录结构
    
    Args:
        base_path: 基础路径
        start_date: 开始日期 (YYYYMMDD)
        end_date: 结束日期 (YYYYMMDD)
        subfolder_range: 子文件夹范围 (起始, 结束)
    """
    # 解析日期
    start = datetime.strptime(start_date, "%Y%m%d")
    end = datetime.strptime(end_date, "%Y%m%d")
    
    # 创建目录结构
    current_date = start
    while current_date <= end:
        # 格式化日期
        date_str = current_date.strftime("%Y%m%d")
        date_path = Path(base_path) / date_str
        
        # 为每一天创建子目录
        for i in range(subfolder_range[0], subfolder_range[1] + 1):
            folder_name = f"{i:03d}"  # 格式化为3位数字，例如 001, 002, ... 030
            folder_path = date_path / folder_name
            
            # 创建目录
            folder_path.mkdir(parents=True, exist_ok=True)
            print(f"已创建目录: {folder_path}")
        
        # 移动到下一天
        current_date += timedelta(days=1)


def create_project_structure():
    """
    创建项目所需的目录结构
    """
    # 创建主要目录
    directories = [
        'data/images',
        'data/audios',
        'data/videos',
        'data/excels',
        'output',
        'temp',
        'docs',
        'static/css',
        'static/js',
        'static/images'
    ]
    
    for directory in directories:
        Path(directory).mkdir(parents=True, exist_ok=True)
        print(f"已创建目录: {directory}")


def main():
    # 创建项目目录结构
    create_project_structure()
    
    # 基础路径（如果需要创建媒体目录结构）
    base_path = r"\\Fw-152\e\媒体部素材\海报推单素材"
    
    # 日期范围
    start_date = "20251001"
    end_date = "20251008"
    
    # 子文件夹范围
    subfolder_range = (1, 30)  # 001 到 030
    
    # 创建目录结构
    create_folder_structure(base_path, start_date, end_date, subfolder_range)
    print("目录结构创建完成!")


if __name__ == "__main__":
    main()